<template>
    <div style="max-width:900px;margin:40px auto;">
        <h2>評論管理</h2>
        <el-table :data="comments" style="width: 100%">
            <el-table-column prop="id" label="ID" width="180"/>
            <el-table-column prop="content" label="內容"/>
            <el-table-column prop="nickname" label="用戶"/>
            <el-table-column prop="gmtCreate" label="評論時間"/>
            <el-table-column label="操作" width="120">
                <template #default="scope">
                    <el-button type="danger" size="small" @click="deleteComment(scope.row.id)">刪除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import axios from 'axios'
const comments = ref([])
const fetchComments = async () => {
    const res = await axios.get('http://localhost:10010/eduservice/edu-comment/getCommentPage/1/100')
    if (res.data && res.data.success) {
        comments.value = (res.data.data.list || []).filter(item => !!item.parentId)
    }
}
const deleteComment = async (id) => {
    await axios.post(`http://localhost:10010/eduservice/edu-comment/delete/${id}`)
    fetchComments()
}
onMounted(fetchComments)
</script> 